package com.af.monitorModule.config;

import com.af.monitorModule.handler.TokenInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    @Autowired
    private TokenInterceptor tokenInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册TestInterceptor拦截器
        InterceptorRegistration registration = registry.addInterceptor(tokenInterceptor);
        //所有路径都被拦截
        registration.addPathPatterns("/**");
        String[] exclude = {
                //登录请求
                "/user/getLogin",
                //脚本心跳
                "/heart/**",
                //工具请求
                "/util/**",
                //数据推送
                "/receive/**",
                //任务执行结果推送
                "/taskResult/push",
                //任务获取
                "/task/get/**",
                //任务结束
                "/task/over/**",
                //索引碎片
                "/fragment/save/**",
                "/fragment/get/**",
                //日志上报接口
                "/log/receive/**",
                "/*/*.html",
                "/*/*.js",
                "/*/*.css",
                "/*/*.woff",
                "/*/*.ttf"};
        //添加不拦截路径
        registration.excludePathPatterns(exclude);
    }
}
